package com.fieldchain.ex.fa100.mvp.model;

import android.graphics.Bitmap;

import com.fieldchain.ex.fa100.access.Constant;
import com.fieldchain.ex.fa100.inter.ImageCallBack;
import com.fieldchain.ex.fa100.inter.IntegerCallBack;
import com.fieldchain.ex.fa100.mvp.base.MyBaseModel;

import java.util.HashMap;

import com.fieldchain.ex.fa100.utils.net.access.HttpRequest;
import com.fieldchain.ex.fa100.utils.net.modle.ImageRequest;
import com.fieldchain.ex.fa100.utils.net.modle.StringRequest;
import com.fieldchain.ex.fa100.utils.screen.MyToast;

/**
 * Created by biyunlong
 * Email: 1225198434@qq.com
 * Data:  2018/9/11
 */
public class ForgetModle extends MyBaseModel {

    public void forget(String smsCode, String userName, final IntegerCallBack callBack) {
        if(smsCode.length()==0){
            MyToast.show("请输入手机验证码");
            return;
        }

        if(userName.length()==0){
            MyToast.show("请输入手机或邮箱账号");
            return;
        }

        HashMap map = new HashMap();
        map.put("password", "");
        map.put("smsCode", smsCode);
        map.put("userName", userName);
        map.put("step", "1");
        HttpRequest.getInstance().postRequest(map, Constant.forget, new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                callBack.index(code);
                MyToast.show(msg);
            }

            @Override
            public void onFaild(Exception e) {
                callBack.index(505);
            }
        });
    }
    public void forget(String password,String smsCode, String userName, final IntegerCallBack callBack) {
        if(password.length()==0){
            MyToast.show("请输入密码");
            return;
        }
        HashMap map = new HashMap();
        map.put("password", password);
        map.put("smsCode", smsCode);
        map.put("userName", userName);
        map.put("step", "2");
        HttpRequest.getInstance().postRequest(map, Constant.forget, new StringRequest() {
            @Override
            public void onSucess(String str, int code, String msg) {
                callBack.index(code);
                MyToast.show(msg);
            }

            @Override
            public void onFaild(Exception e) {
                callBack.index(505);
            }
        });
    }

    public void getVer(final ImageCallBack callBack) {
        HttpRequest.getInstance().getImage(Constant.image,new ImageRequest() {
            @Override
            public void imgReceive(Bitmap bit) {
                callBack.imageReceive(bit);
            }
        });
    }

    @Override
    public void detachView() {

    }
}
